package com.pphh.demo;

import com.netflix.hystrix.HystrixCommandProperties;
import com.pphh.demo.exception.BlockException;

/**
 * Please add description here.
 *
 * @author huangyinhuang
 * @date 11/22/2018
 */
public class HystricSyncFlowControl extends FlowControl {

    private HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy;

    public HystricSyncFlowControl(HystrixCommandProperties.ExecutionIsolationStrategy isolationStrategy) {
        this.isolationStrategy = isolationStrategy;
    }

    @Override
    public void run() throws BlockException {
        TestCommand command = new TestCommand(this, this.isolationStrategy);
        String result = command.execute();
        if (TestCommand.FAIL.equals(result)) {
            throw new BlockException("task is blocked by hystrix.");
        }
    }

    public HystrixCommandProperties.ExecutionIsolationStrategy getIsolationStrategy() {
        return isolationStrategy;
    }

}
